import os
import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from log import logger


def ktjk(driver, web, *args, **kwargs):
    file_path = kwargs.get('files')

    driver.get('https://h-vpp.techstar.com.cn:8090/vpp/user-manage')
    web.until(
        EC.visibility_of_element_located((
            By.XPATH, "//*[contains(text(), '空调集控系统')]"
        ))
    ).click()
    # 获取所有打开的窗口的句柄
    window_handles = driver.window_handles
    # 切换到第二个Tab（最新打开的窗口）
    driver.switch_to.window(window_handles[-1])
    logger.info('切换到空调集控系统界面')
    # # driver.get('https://h-vpp.techstar.com.cn:8888/player/base?id=1701164171262779392')
    web.until(EC.visibility_of_element_located((By.XPATH, "//*[contains(text(), '空调集控')]")))
    time.sleep(5)
    pic = os.path.join(file_path, '空调集控.png')
    driver.save_screenshot(pic)

    web.until(EC.visibility_of_element_located((By.XPATH, "//*[contains(text(), '结构树管理')]"))).click()
    time.sleep(5)
    pic = os.path.join(file_path, '结构树管理.png')
    driver.save_screenshot(pic)
    # driver.save_screenshot('结构树管理.png')
    web.until(EC.visibility_of_element_located((By.XPATH, "//*[contains(text(), '能耗分析')]"))).click()
    time.sleep(5)
    pic = os.path.join(file_path, '能耗分析.png')
    driver.save_screenshot(pic)
    # driver.save_screenshot('能耗分析.png')
    web.until(EC.visibility_of_element_located((By.XPATH, "//*[contains(text(), '操作日志')]"))).click()
    time.sleep(5)
    pic = os.path.join(file_path, '操作日志.png')
    driver.save_screenshot(pic)
    # driver.save_screenshot('操作日志.png')
    logger.info('空调集控系统巡检完成')
